package com.atguigu.tingshu.order.interceptor.impl;

import com.atguigu.tingshu.order.context.SaveOrderStrategyContext;
import com.atguigu.tingshu.order.interceptor.OrderHandlerInterceptor;
import com.atguigu.tingshu.order.strategy.SaveOrderStrategy;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class SavaOrderOrderHandlerInterceptor implements OrderHandlerInterceptor {

    @Override
    public OrderInfoVo sbumitOrderRequestProcess(OrderInfoVo orderInfoVo) {

        /**
         * 用户选择的支付方式不同，生成订单的业务逻辑不同。为了提高代码的维护性和后期的扩展性，可以使用策略设计模式进行改造。
         */
        String payWay = orderInfoVo.getPayWay();
        SaveOrderStrategy saveOrderStrategy = SaveOrderStrategyContext.getSaveOrderStrategy(payWay);
        return saveOrderStrategy.saveOrderInfo(orderInfoVo);
    }

    @Override
    public int sort() {
        return 3;
    }

}
